package com.example.demo.controller;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.model.History;
import com.example.demo.repository.HistoryRepository;

@Controller
@RequestMapping("/history")
public class HistoryController {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	HistoryRepository historyRepository;
	
	@RequestMapping("/findall")
	@ResponseBody
	@CrossOrigin
	public List<History> findAll() {
		logger.info("HistoryController: findAll()");
		return historyRepository.findAll();
	}
	
	@RequestMapping("/find")
	@ResponseBody
	@CrossOrigin
	public List<History> findByAid(@RequestParam String aid) {
		//适配原有程序，需要返回数组
		logger.info("HistoryController: findByAid()");
		List<History> h = new ArrayList<History>();
		h.add(historyRepository.findByAid(aid));
		return h;
	}
}
